=== Post Expiry Redirect ===
Contributors:      nomenlink
Tags:              expiry, redirect, post expiration, scheduled redirect, content management
Requires at least: 6.0
Tested up to:      6.9.4
Requires PHP:      8.0
Stable tag:        1.0.0
License:           GPLv2 or later
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Set an expiry date on any post or page and automatically redirect visitors to a URL of your choice when the date passes.

== Description ==

**Post Expiry Redirect** lets you define a precise expiry date for any post or page. Once the date is reached, visitors are silently redirected — with a 301 (permanent) or 302 (temporary) HTTP code — to any URL you choose: a new article, a category archive, your homepage, or an external site.

A daily email notification warns the site administrator X days before a post expires, so you are never caught off guard.

= Key features =

* **Date picker metabox** — set expiry date, redirect URL, and redirect type (301/302) directly from the post editor sidebar.
* **Automatic redirect** — uses WordPress's `template_redirect` hook; zero performance overhead on non-expired content.
* **Visual admin badge** — a color-coded badge in the Posts/Pages list shows upcoming (green) and expired (red) content at a glance.
* **Daily email alert** — WP-Cron sends an email to the site admin listing posts that will expire within a configurable number of days.
* **Bulk action** — select multiple posts and remove their expiry settings in one click with the *Remove Expiry* bulk action.
* **Settings page** — configure how many days before expiry the notification email is sent (*Settings > Post Expiry*). Set to 0 to disable emails entirely.
* **Lightweight** — single PHP file, no JavaScript, no CSS files, no external dependencies.
* **Developer-friendly** — fully object-oriented, nonces on every form, all output escaped, all input sanitized, fully translation-ready.

= Use cases =

* Seasonal promotions and limited-time offers — redirect to a "sale ended" page automatically.
* Event announcements — redirect to post-event recap or registration-closed page.
* Job listings — redirect expired listings to a general careers page.
* News articles with an embargo — schedule when a post becomes a redirect without manual intervention.
* Legal or compliance content that must be retired — ensure stale content is never served again.

= How it works =

1. Open any post or page editor.
2. Find the **Expiry & Redirect** panel in the sidebar.
3. Pick an expiry date, enter the destination URL, and choose 301 or 302.
4. Save. That's it — WordPress handles the rest automatically.

== Installation ==

= From the WordPress dashboard =

1. Go to **Plugins → Add New Plugin**.
2. Search for **Post Expiry Redirect**.
3. Click **Install Now**, then **Activate**.

= Manual upload =

1. Download the `.zip` file.
2. Go to **Plugins → Add New Plugin → Upload Plugin**.
3. Choose the zip file and click **Install Now**, then **Activate**.

= Via FTP =

1. Unzip and upload the `post-expiry-redirect` folder to `/wp-content/plugins/`.
2. Activate the plugin from the **Plugins** screen.

== Frequently Asked Questions ==

= Does this work with custom post types? =

The metabox currently appears on `post` and `page`. Support for custom post types can be added by filtering the third argument of `add_meta_box` in a child theme or mu-plugin. A dedicated filter will be added in a future release.

= What happens if I only set a date but no redirect URL? =

Nothing. Both the date and the redirect URL must be set for a redirect to occur. If the URL field is empty, visitors will see the post as normal even after the expiry date.

= Will the redirect fire for logged-in administrators? =

Yes. The redirect applies to everyone, including administrators. This makes it easy to verify the redirect works correctly after publishing.

= How do I disable the email notifications? =

Go to **Settings → Post Expiry** and set the *Notify X days before expiry* field to **0**.

= Does the plugin delete the post when it expires? =

No. The post stays published. Only a redirect is issued to visitors. You keep full control over the content.

= What happens when I deactivate the plugin? =

The scheduled cron event is automatically removed. All post meta (expiry date, URL, type) is preserved in the database so you can reactivate without losing your settings.

= Is the plugin GDPR-compliant? =

Yes. The plugin stores only the expiry date, redirect URL, and redirect type as post meta. No personal data from visitors is collected or stored.

== Screenshots ==

1. The **Expiry & Redirect** metabox in the post editor sidebar.
2. Color-coded expiry badges in the Posts admin list (green = upcoming, red = expired).
3. The Settings page where you configure the notification lead time.
4. Example email notification sent to the site administrator.

== Changelog ==

= 1.0.0 — 2026-03-23 =
* Initial release.
* Metabox with date picker, redirect URL, and 301/302 selector.
* Automatic front-end redirect via `template_redirect`.
* Admin column with green/red expiry badge.
* Bulk action: Remove Expiry.
* Daily WP-Cron email notification.
* Settings page for notification lead time.

== Upgrade Notice ==

= 1.0.0 =
First public release. No upgrade steps required.
